﻿(function (window) {
    function Coin() {
        this.initialize();
    }

    var p = Coin.prototype = new createjs.Container();
    p.Container_initialize = p.initialize;
    p.initialize = function () {

        this.Container_initialize();

        this.velX = 0;
        this.velY = 0;
        this.velR = 0;
        this.lastUpdate = 0;


        var bm = new createjs.Bitmap(preload.getResult("coin3"));
        bm.x = -48 / 2;
        bm.y = -48 / 2;
        this.addChild(bm);
        

    };

    p.explode = function () {

        this.lastUpdate = Date.now();
        this.velX = (Math.random() * 120 - 60) * this.scaleX;
        this.velY = (Math.random() * 80 ) * this.scaleX;
        this.velR = Math.random() * 30 - 15;
    };

    p.updateExplode = function () {
        var c = (Date.now() - this.lastUpdate) / 100;
        this.lastUpdate = Date.now();
        this.velX *= (1 - (c * 0.02));
        this.velY += (8 * this.scaleX * c);
        this.x += this.velX * c;
        this.y += this.velY * c;
        this.rotation += (this.velR * c);
    };
    window.Coin = Coin;

}(window));
